package beans;

import java.io.Serializable;
import java.util.Locale;

import javax.annotation.ManagedBean;
import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

@ManagedBean
@SessionScoped
public class MBLanguage implements Serializable {
  
  private Locale currentLocale;

  /**
   * Cria uma nova instância de MBLanguage
   */
  public MBLanguage() {}
  
  public void changeLanguage(ActionEvent clickEvent) {

    FacesContext context = FacesContext.getCurrentInstance();
    currentLocale = context.getViewRoot().getLocale();

    if (currentLocale.equals(Locale.ENGLISH)) {
      currentLocale = new Locale("pt", "BR");
    } else {
      currentLocale = Locale.ENGLISH;
    }

    context.getViewRoot().setLocale(currentLocale);
  }
}
